package Z.dailyExercise._0107;

import java.util.Arrays;

public class _1491_去掉最低工资和最高工资后的工资平均值 {
    //直接调用sort函数
    public double average(int[] salary) {

        Arrays.sort(salary);
        int c =0;
        for (int i=1;i<salary.length-1;i++){
            c+=salary[i];
        }
        return (double)c/(salary.length-2);
    }

    //不利用sort
    public double average1(int[] salary) {
        double sum =0;
        double Max = Integer.MIN_VALUE;
        double Min = Integer.MAX_VALUE;
        for (int i=0;i<salary.length;i++){
            sum += salary[i];
            Max = Math.max(Max,salary[i]);
            Min = Math.min(Min,salary[i]);
        }

        return (sum-Max-Min)/(salary.length-2);
    }



    }
